﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.geom.*;
    import org.aswing.error.*;

    public class AsWingManager {

        private static var stage:Stage = null;
        private static var ROOT:DisplayObjectContainer = null;
        private static var INITIAL_STAGE_WIDTH:int;
        private static var INITIAL_STAGE_HEIGHT:int;
        private static var timer:Timer;
        private static var nextFrameCalls:Array = new Array();
        private static var preventNullFocus:Boolean = true;
        private static var frameTrigger:Sprite;

        public static function setRoot(_arg1:DisplayObjectContainer):void{
            ROOT = _arg1;
            if (((((!((_arg1 == null))) && ((stage == null)))) && (!((_arg1.stage == null))))){
                initStage(_arg1.stage);
            };
        }
        public static function initAsStandard(_arg1:DisplayObjectContainer, _arg2:Boolean=true, _arg3:Boolean=false):void{
            setRoot(_arg1);
            if (stage){
                stage.align = StageAlign.TOP_LEFT;
                stage.scaleMode = StageScaleMode.NO_SCALE;
                stage.stageFocusRect = false;
            };
            preventNullFocus = _arg2;
            RepaintManager.getInstance().setAlwaysUseTimer(_arg3);
        }
        public static function setPreventNullFocus(_arg1:Boolean):void{
            preventNullFocus = _arg1;
        }
        public static function isPreventNullFocus():Boolean{
            return (preventNullFocus);
        }
        public static function setInitialStageSize(_arg1:int, _arg2:int):void{
            INITIAL_STAGE_WIDTH = _arg1;
            INITIAL_STAGE_HEIGHT = _arg2;
        }
        public static function getInitialStageSize():IntDimension{
            if (ROOT == null){
                throw (new AsWingManagerNotInited());
            };
            return (new IntDimension(INITIAL_STAGE_WIDTH, INITIAL_STAGE_HEIGHT));
        }
        public static function getRoot(_arg1:Boolean=true):DisplayObjectContainer{
            if (ROOT == null){
                return (getStage(_arg1));
            };
            return (ROOT);
        }
        static function initStage(_arg1:Stage):void{
            if (stage == null){
                stage = _arg1;
                INITIAL_STAGE_WIDTH = stage.stageWidth;
                INITIAL_STAGE_HEIGHT = stage.stageHeight;
            };
        }
        static function isStageInited():Boolean{
            return (!((stage == null)));
        }
        public static function getStage(_arg1:Boolean=true):Stage{
            if (((_arg1) && ((stage == null)))){
                throw (new AsWingManagerNotInited());
            };
            return (stage);
        }
        public static function updateAfterMilliseconds(_arg1:int=20):void{
            if (timer == null){
                timer = new Timer(_arg1, 1);
                timer.addEventListener(TimerEvent.TIMER, __update);
            };
            if (!timer.running){
                timer.reset();
                timer.start();
            };
        }
        public static function callNextFrame(_arg1:Function):void{
            if (frameTrigger == null){
                frameTrigger = new Sprite();
                frameTrigger.addEventListener(Event.ENTER_FRAME, __enterFrame);
            };
            nextFrameCalls.push(_arg1);
        }
        public static function callLater(_arg1:Function, _arg2:int=40):void{
            var func:* = _arg1;
            var time:int = _arg2;
            var timer:* = new Timer(time, 1);
            timer.addEventListener(TimerEvent.TIMER, function (_arg1:TimerEvent):void{
                func();
            });
            timer.start();
        }
        private static function __update(_arg1:TimerEvent):void{
            _arg1.updateAfterEvent();
        }
        private static function __enterFrame(_arg1:Event):void{
            var _local4:Function;
            var _local2:Array = nextFrameCalls;
            nextFrameCalls = new Array();
            var _local3:int;
            while (_local3 < _local2.length) {
                _local4 = _local2[_local3];
                _local4();
                _local3++;
            };
        }

    }
}//package org.aswing 
